<?php

use yii\db\Schema;
use yii\db\Migration;

class m160316_071213_add_flow_pmp_tables extends Migration
{
    public function up()
    {
        $sql = <<<FINE
drop table if exists {{%flow_pmp}};
create table if not exists {{%flow_pmp}} (
  id int(10) unsigned not null auto_increment,
  guid int(9) not null comment 'pmp guid',
  name varchar(128) not null comment '交易名称',
  buyer_guid int(8) not null comment '关联用户的 guid',
  advertiser varchar(64) not null comment '广告主',
  pmp_price decimal(10,2) not null comment '交易底价，按 cpm 计算',
  can_be_rtb tinyint(1) not null default 1 comment '剩余资源是否可rtb再售卖, 1 可以，0不可以',
  resource_standard text comment '文字描述的定向需求',
  purchase_amount text comment '文字描述的采购量, 如300cpm',
  lifespan int(1) not null default '1' comment '1 不限时间， 2 限时',
  start_date date default null comment '交易开始时间, lifespan=2 有效',
  end_date date default null comment '交易结束时间, lifespan=2 有效',
  status int(8) not null default '1' comment '广告位状态 0 暂停， 1 活动， 2 删除',
  creator int(8) not null default '17410171' comment 'last modifier guid',
  created_at timestamp not null default current_timestamp,
  modified_at timestamp not null default '0000-00-00 00:00:00',
  primary key (id)
)engine=innodb default charset=utf8;

drop table if exists {{%flow_pmp_adspace_map}};
create table if not exists {{%flow_pmp_adspace_map}} (
  id int(10) unsigned not null auto_increment,
  flow_pmp_guid int(9) unsigned not null comment 'flow pmp 表 guid',
  adspace_guid bigint(10) not null comment '广告位的纯数字唯一键，全库唯一',
  adspace_title varchar(100) not null comment '广告位名称',
  adspace_class_id tinyint(1) not null default 1 comment '1 display adspace, 2 pc video, 3 mobile banner, 4 mobile video',
  status int(8) not null default '1' comment '广告位状态 0 无效， 1 有效',
  creator int(8) not null default '17410171' comment 'last modifier guid',
  created_at timestamp not null default current_timestamp,
  modified_at timestamp not null default '0000-00-00 00:00:00',
  primary key (id)
)engine=innodb default charset=utf8;

FINE;
        $this->execute($sql);
    }

    public function down()
    {
        $this->dropTable('{{%flow_pmp}}');
        return $this->dropTable('{{%flow_pmp_adspace_map}}');
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
     */
}
